#ifndef CLOSEBUTTON_H
#define CLOSEBUTTON_H

#include <QPushButton>
#include <QString>
#include <QWidget>

class Button : public QPushButton
{
    Q_OBJECT
    Q_PROPERTY(int curIndex READ getcurIndex WRITE setcurIndex)

public:
    // FileName - 图片路径, xnum - 水平方向图片个数(列数), parent - 父窗口指针
    // ynum - 垂直方向图片个数(行数), bkGrnd - 背景图片路径
    Button(QWidget *parent = NULL);
    Button( QString FileName, int xnum  = 1,  QWidget *parent = 0, int ynum = 1, QString bkGrnd = NULL);
    Button(QVector<QString> list, QWidget *parent = 0, QString bkGrnd = NULL);
    void setPixmapList(QVector<QString> &list);
    void setPixmapList(QString fileName, int xNum = 1, int yNum = 1);

    // 内联函数
    // 设置按钮为选中状态
    void setSelect(int index = 2)
    {
        setcurIndex(index);
        m_isToggle = true;
    }
    // 设置按钮为普通未选中状态
    void setNormal(int index = 0)
    {
        setcurIndex(index);
        m_isToggle = false;
    }
    // 获取设置的图片状态列表
    QVector<QPixmap> *getPixmapList(void)
    {
        return &m_pixmapList;
    }
    // 设置当前图片状态
    void setcurIndex(int index)
    {
        m_curIndex = index;
        update();
    }
    // 获取当前图片状态
    int getcurIndex(void){
        return m_curIndex;
    }

protected:
    virtual void paintEvent ( QPaintEvent * event);
    virtual void enterEvent(QEvent *event);
    virtual void leaveEvent ( QEvent * event );
    virtual void mousePressEvent ( QMouseEvent * event ) ;
    virtual void mouseReleaseEvent ( QMouseEvent * event );
    virtual  QSize sizeHint () const;

private:
    void getImages(QString fileName, int xNum = 1, int yNum = 1);

private:
    QVector<QPixmap> m_pixmapList;
    int m_curIndex;
    // 是不是开关型按钮(按下之后不会弹起)
    // true -> 开关型, 按下不会弹起
    // false -> 非开关型, Q弹
    bool m_isToggle;
    QPixmap *m_background;
};

#endif // CLOSEBUTTON_H
